package com.dd.duu.controller;

import com.dd.dc.entity.users.DPermission;
import com.dd.duu.service.PermissionClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 描述:
 *
 * @author: yanglin
 * @Date: 2021-03-08-15:25
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/")
public class IndexController {

    @Autowired
    PermissionClient permissionClient;

    @GetMapping("/index")
    public ModelAndView index(){
        log.info("进入主页面.............");
        ModelAndView modelAndView = new ModelAndView("index");
        // 用户信息
        modelAndView.addObject( "loginUser", null);
        List<DPermission> permissions = permissionClient.findPermissionByUserId(1);
        // 用户菜单
        modelAndView.addObject( "menuList", permissions);
        return modelAndView;
    }


    @GetMapping("/user")
    public ModelAndView user(){
        log.info("进入用户管理.............");
        ModelAndView modelAndView = new ModelAndView("/user/user");
        return modelAndView;
    }

    @GetMapping("/userEdit")
    public ModelAndView userEdit(@RequestParam String eq){
        log.info("进入用户编辑.............{}, {}", eq);
        ModelAndView modelAndView = new ModelAndView("/user/userEdit");
        modelAndView.addObject( "eq", eq);
        return modelAndView;
    }

    @GetMapping("/role")
    public ModelAndView role(){
        log.info("进入角色管理.............");
        ModelAndView modelAndView = new ModelAndView("/role/role");
        return modelAndView;
    }

    @GetMapping("/roleEdit")
    public ModelAndView roleEdit(@RequestParam String eq){
        log.info("进入角色编辑.............{}, {}", eq);
        ModelAndView modelAndView = new ModelAndView("/role/roleEdit");
        modelAndView.addObject( "eq", eq);
        return modelAndView;
    }

    @GetMapping("/permission")
    public ModelAndView menu(){
        log.info("进入菜单权限管理.............");
        ModelAndView modelAndView = new ModelAndView("/permission/permission");
        return modelAndView;
    }

    @GetMapping("/permissionEdit")
    public ModelAndView menuEdit(@RequestParam String eq){
        log.info("进入菜单编辑.............{}, {}", eq);
        ModelAndView modelAndView = new ModelAndView("/permission/permissionEdit");
        modelAndView.addObject( "eq", eq);
        return modelAndView;
    }

    @GetMapping("/code")
    public ModelAndView code(){
        log.info("进入数据字典.............");
        ModelAndView modelAndView = new ModelAndView("/code/code");
        return modelAndView;
    }

    @GetMapping("/codeEdit")
    public ModelAndView codeEdit(@RequestParam String eq){
        log.info("进入数据字典编辑.............{}, {}", eq);
        ModelAndView modelAndView = new ModelAndView("/code/codeEdit");
        modelAndView.addObject( "eq", eq);
        return modelAndView;
    }

    @GetMapping("/level")
    public ModelAndView level(){
        log.info("进入用户等级.............");
        ModelAndView modelAndView = new ModelAndView("/level/level");
        return modelAndView;
    }

    @GetMapping("/levelEdit")
    public ModelAndView levelEdit(@RequestParam String eq){
        log.info("进入数据字典编辑.............{}, {}", eq);
        ModelAndView modelAndView = new ModelAndView("/level/levelEdit");
        modelAndView.addObject( "eq", eq);
        return modelAndView;
    }

}
